<?php

namespace globalunit\logic;

use globalunit\utils\CoroutineCurl;
use globalunit\utils\GenID;
use QYS\Db\Mysql;
use QYS\Db\Mongo;
use QYS\Db\Redis;
use QYS\Log\Log;
use QYS\Core\Config;
use globalunit\utils\KeysUtil;
use globalunit\model\UserModel;

class UserLogic
{

    public static function loaduser($id)
    {
        $u = new UserModel();
        $ok = $u->get("id = {$id}");
        if (!$ok) {
            return null;
        }
        return $u->toArray();
    }


    public static function register($rediscli, $data){
        $uid = GenID::genid($rediscli);
        $u = new UserModel();
        $u->id = $uid;
        $u->phone = $data['phone'];
        $u->organize_id = $data['organize_id'];
        $u->appid = $data['appid'];
        $u->pfid = $data['pfid'];
        $u->is_login = 1;
        $ok = $u->insert();
        if($ok){
            return $u->toArray();
        }else{
            return null;
        }
    }


    public static function login($id){
        $u = new UserModel();
        $u->get("id = {$id}");
        $u->is_login = 1;
        $u->last_login_time = date("Y-m-d H:i:s");
        return $u->save();
    }

    public static function loaduserbyphone($appid, $phone)
    {
        $u = new UserModel();
        $ok = $u->get("appid = '{$appid}' and phone = '{$phone}'");
        if (!$ok) {
            return null;
        }
        return $u->toarray();
    }
}
